<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\BaseController;
use think\Request;
use app\model\Role as RoleModel;
use app\model\Rule;
class Role extends BaseController
{
    public function index()
    {

      $data=  RoleModel::order('id','asc')->paginate(10)->map(function($item){
            if($item['id']==1){
                $item['rule_id']=implode(',',Rule::where('status',1)->column('id'));
                return $item;
            }
            return $item;
        });
        return $this->success($data);
    }


    public function create()
    {
        return $this->success(RoleModel::create(request()->param()));
    }


    public function update($id)
    {

        return $this->success(RoleModel::where('id',$id)->update(request()->param()));
    }

    public function delete($id)
    {
        return $this->success(RoleModel::where('id',$id)->delete());
    }
}
